#include "device_virtual_dev.h"
#include "SystemIO.h"
#include <stdlib.h>

device_virtual_dev::device_virtual_dev( void )
{

}

device_virtual_dev::device_virtual_dev( char * devPath )
{
	memset(_dev_path, 0, sizeof(_dev_path));
	strncpy(_dev_path,devPath,256);
}


device_virtual_dev::~device_virtual_dev( void )
{

}

int device_virtual_dev::open()
{
	return 0;
}

int device_virtual_dev::close()
{
	return 0;
}

int device_virtual_dev::send_data( unsigned char * request, int request_len )
{
	memcpy(reps, request, request_len);
	int ret = SystemIO(reps, (unsigned int*)&request_len);
	reps_len = request_len;
	return 0;
}

int device_virtual_dev::receive_data( unsigned char * response, int *response_len )
{
	memcpy(response, reps, reps_len);
	*response_len = reps_len;
	return 0;
}

int device_virtual_dev::device_io( unsigned char * request, int request_len,unsigned char * response, int *response_len )
{
	if( 0 != send_data(request, request_len))
	{
		return 1;
	}

	if(0 != receive_data(response, response_len))
	{
		return 2;
	}
    
    return 0;
}

int device_virtual_dev::set_comm_timeout( int time_out )
{
	return 0;
}

char * device_virtual_dev::get_dev_path()
{
	return _dev_path;
}

char * device_virtual_dev::get_dev_name()
{
	return _dev_path;
}

